package src.jdbc3;

import org.junit.Test;

import java.sql.*;

public class jdbcStudy4 {
    //登录系统
    @Test
    public void isAdmin() throws SQLException {
        String url="jdbc:mysql://localhost:3306/stu?useSSL=false&serverTimezone=UTC";
        String username="root";
        String password="";
        Connection connection = DriverManager.getConnection(url, username, password);
        //定义sql
        String sql="select * from tbl_lixue where username=? and password=?";
        //获取预编译的对象
        PreparedStatement statement = connection.prepareStatement(sql);
        //输入？的值
        statement.setString(1,"ooo");
        statement.setString(2,"8888");
        //执行sql语句
        ResultSet resultSet = statement.executeQuery();
        if (resultSet.next()){
            System.out.println("登陆成功");
        }else{
            System.out.println("非法管理员");
        }
        //释放资源
        statement.close();
        connection.close();
    }
}
